<template>
  <div class="currency-box">
    <div class="left">
      <!-- 工单列表的搜索 Start -->
      <header>
        <div class="search">
          <a-input
            placeholder="输入单号"
            v-model="searchInfo.keyWords"
            @keyup.enter="upList"
          />
        </div>
        <div class="icon">
          <a-popover
            placement="bottom"
            trigger="click"
            v-model="visible"
            title="筛选"
          >
            <template slot="content">
              <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol">
                <a-form-model-item label="填写时间">
                  <a-range-picker
                    @change="onTimeChange"
                    :defaultValue="defaultdateList"
                  />
                </a-form-model-item>
                <a-form-model-item label="厂区">
                  <a-select
                    :allowClear="true"
                    mode="multiple"
                    :maxTagCount="1"
                    class="selectwidth"
                    v-model="searchInfo.WSType"
                    placeholder="请选择"
                    @change="handleChange"
                  >
                    <a-select-option
                      v-for="item in WSTypeList"
                      :key="item.type"
                      :value="item.type"
                      >{{ item.name }}</a-select-option
                    >
                  </a-select>
                </a-form-model-item>
                <a-form-model-item label="车间">
                  <a-select
                    :allowClear="true"
                    mode="multiple"
                    class="selectwidth"
                    v-model="searchInfo.SegmentIDs"
                    placeholder="请选择"
                  >
                    <a-select-option
                      v-for="item in QSegmentList"
                      :key="item.type"
                      :value="item.type"
                      >{{ item.name }}</a-select-option
                    >
                  </a-select>
                </a-form-model-item>
                <a-form-model-item label="生产批号">
                  <a-input v-model="searchInfo.batchNo" />
                </a-form-model-item>
                <a-form-model-item label="计划单号">
                  <a-input v-model="searchInfo.packingPlanNo" />
                </a-form-model-item>
                <a-form-model-item label="产品编码">
                  <a-input v-model="searchInfo.materialCode" />
                </a-form-model-item>
                <a-form-model-item label="状态">
                  <a-select
                    style="width: 100%"
                    v-model="jobRecordStatusData"
                    mode="multiple"
                    :maxTagCount="1"
                  >
                    <a-select-option
                      :value="item.num"
                      v-for="item in jobRecordStatusList"
                      :key="item.num"
                    >
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-form-model-item>

                <a-form-model-item
                  style="display: flex; justify-content: flex-end"
                >
                  <a-button class="default-button" @click="upList">
                    查询
                  </a-button>
                </a-form-model-item>
              </a-form-model>

              <!-- <div style="display: flex; justify-content: flex-end;">
                                
                            </div> -->
            </template>
            <a-icon type="filter" class="icon-class" />
          </a-popover>
        </div>
      </header>
      <!-- 工单列表的搜索 End -->
      <!-- 工单列表的展示 Start -->
      <section
        v-if="list.length == 0"
        style="position: relative; top: 50%; left: 25%"
      >
        <img src="@/assets/svg/none-list.svg" alt="" />
      </section>

      <section
        v-else
        infinite-scroll-immediate-check="false"
        infinite-scroll-listen-for-event="false"
        v-infinite-scroll="handleinfiniteOnLoad"
        infinite-scroll-disabled="busy"
        infinite-scroll-distance="20"
      >
        <div
          :class="[
            'section-box',
            index == currentIndex ? 'section-active' : '',
          ]"
          v-for="(item, index) in list"
          :key="index"
          @click="checkPacking(item, index)"
        >
          <div class="section-box-info">
            <p class="dimension-text">
              计划单号:{{ item.PackingPlanNo || "/" }}
            </p>
            <p class="dimension-text">
              产品编码:{{ item.MaterialCode || "/" }}
            </p>
            <p class="dimension-text">
              产品名称:{{ item.MaterialName || "/" }}
            </p>
            <p>单据类型:{{ mateFind(item.OrderType).name || "/" }}</p>
            <p>生产批号:{{ item.BatchNo || "/" }}</p>
            <p>厂区:{{ item.WSName || "/" }}</p>
            <p>车间:{{ item.SegmentName || "/" }}</p>
            <p>状态:{{ item.JobRecordStatusStr || "/" }}</p>
          </div>
        </div>
      </section>

      <!-- 工单列表的展示 End -->
    </div>
    <a-spin
      :spinning="loading"
      tip="加载中..."
      size="large"
      class="right batch-printing-right"
    >
      <div class="spin-box-div">
        <!-- 选择该工单的批记录 Start -->
        <header>
          <div
            class="type-list-box"
            style="height: 100%"
            v-show="batchList.length == 0"
          >
            <div class="info-box">
              <span>暂无绑定项</span>
            </div>
          </div>

          <div
            v-for="(itm, idx) in batchList"
            :key="idx"
            :class="['type-list-box', idx == mateIdx ? 'active' : '']"
          >
            <article class="article-list-box">
              <div class="article-top" @click="checkBatch(itm, idx)">
                <!-- <div class="info-box">
                  <span>工作集:</span><span>{{ itm.JobGroupName }}</span>
                </div> -->
              </div>
              <div class="info-box">
                <!-- <span>操作:</span> -->
                <span>
                  <general-button
                    class="default-button"
                    size="small"
                    @operation="onPrint"
                    :btnDisabled="idx != mateIdx"
                    :loading="startPrint"
                    btnText="打印"
                    btnPowerNum="E8F94A1A-2012-4E11-B650-544C8527EF5C"
                  >
                  </general-button>
                  <general-button
                    style="margin-left: 5px"
                    class="default-button"
                    size="small"
                    @operation="onAppointPrint"
                    :btnDisabled="idx != mateIdx"
                    :loading="startPrint"
                    btnText="指定打印"
                    btnPowerNum="E8F94A1A-2012-4E11-B650-544C8527EF5C"
                  >
                  </general-button>
                  <general-button
                    style="margin-left: 5px"
                    class="default-button"
                    size="small"
                    @operation="onExamine"
                    btnPowerNum="E29C145E-8006-435C-A35A-24091CA67C14"
                    :btnDisabled="idx != mateIdx"
                    btnText="审核"
                  >
                  </general-button>
                  <general-button
                    style="margin-left: 5px"
                    class="default-button"
                    size="small"
                    @operation="onUnExamine"
                    btnPowerNum="E29C145E-8006-435C-A35A-24091CA67C14"
                    :btnDisabled="idx != mateIdx"
                    btnText="弃审"
                  >
                  </general-button>
                </span>
              </div>
            </article>
          </div>
        </header>
        <!-- 选择该工单的批记录 End -->
        <section
          v-if="
            mateCurrentInfo.JobRecordList != null &&
            mateCurrentInfo.JobRecordList.length == 0
          "
        >
          <img
            src="@/assets/svg/none-list.svg"
            alt=""
            style="position: relative; top: 50%; left: 50%"
          />
        </section>
        <section v-else style="margin: 10px 0" ref="print">
          <div
            v-for="(item, index) in mateCurrentInfo.JobRecordList"
            :key="item.JobRecordID"
          >
            <div
              :class="[
                !item.noData ? 'print-inside' : '',
                item.IsPaging ? 'print-box' : '',
              ]"
              v-if="!item.noData"
            >
              <div
                :class="item.IsPaging ? 'table-margin' : ''"
                v-if="
                  item.JobRecordDetaiList != null &&
                  item.JobRecordDetaiList.length != 0 &&
                  item.JobTempletIndex == 1
                "
              >
                <!-- 需要打印且展示的部分 Start -->
                <batch-box
                  v-if="item.TableType == 1"
                  :list="item.JobRecordDetaiList"
                  :item="item"
                  :mateCurrentInfo="item"
                ></batch-box>
                <!-- 需要打印且展示的部分 End  -->

                <!-- 聚合表单 Start -->
                <polymerize-box
                  v-if="item.TableType == 2 || item.TableType == 3"
                  :isShowBody="true"
                  :list="item.JobRecordDetaiList"
                  :item="item"
                  :headerList="item.JobRecordDetaiHList"
                  :mateCurrentInfo="item"
                ></polymerize-box>
                <!-- 聚合表单 End -->
              </div>
              <div
                v-if="
                  item.JobRecordDetaiList != null &&
                  item.JobRecordDetaiList.length != 0 &&
                  item.JobTempletIndex != 1
                "
              >
                <!-- 需要打印且展示的部分 Start -->
                <batch-box
                  v-if="item.TableType == 1"
                  :list="item.JobRecordDetaiList"
                  :item="item"
                  :lastItem="mateCurrentInfo.JobRecordList[index - 1]"
                  :mateCurrentInfo="item"
                ></batch-box>
                <!-- 需要打印且展示的部分 End  -->

                <!-- 聚合表单 Start -->
                <polymerize-box
                  :isShowBody="true"
                  v-if="item.TableType == 2 || item.TableType == 3"
                  :list="item.JobRecordDetaiList"
                  :item="item"
                  :lastItem="mateCurrentInfo.JobRecordList[index - 1]"
                  :mateCurrentInfo="item"
                  :headerList="item.JobRecordDetaiHList"
                ></polymerize-box>
                <!-- 聚合表单 End -->
              </div>
            </div>
          </div>
        </section>
      </div>
    </a-spin>
  </div>
</template>

<script>
import {
  getJobRecordToPackingPlanID,
  getJobRecordToPacking,
  getPackingPlanList,
  getJobRecordToList,
  getJobRecordDetailList,
  getJobRecordDetailGroupList,
  verifyJobRecord,
  unVerifyJobRecord,
} from "@/api/JobRecord";
import moment from "moment";
import BatchBox from "@/views/batch-printing/children/batch-table-box.vue";
import PolymerizeBox from "@/views/batch-printing/children/polymerize-table-box.vue";
import PrintDrawer from "@/views/batch-printing/children/print-drawer.vue";
import EditBatch from "@/views/batch-printing/children/edit-batch.vue";
import GeneralButton from "@/components/be-current-btn.vue";
import polymerizeTitle from "@/common/handle-title";
import { GetWorkShopTypesAll } from "@/api/WorkShopType/index";
import { GetSegments } from "@/api/NBCSegment/index";
import { debounce } from "@/common/debounce";
import { mapState } from "vuex";
export default {
  name: "AuditTotalJobRecord",
  components: {
    BatchBox,
    PolymerizeBox,
    PrintDrawer,
    EditBatch,
    GeneralButton,
  },
  data() {
    return {
      loadingNum: 0, //loading的总次数
      isRequest: false, //是否可以请求
      loading: false, //加载完成
      jobRecordStatusData: [12], //当前状态
      WSTypeList: [], //厂区列表
      QSegmentList: [], //车间列表
      currentIndex: 0, //当前选中
      jobRecordStatusList: [
        { name: "未创建", num: 0 },
        { name: "已创建未填写", num: 10 },
        { name: "填写中", num: 11 },
        { name: "已填写未审核", num: 12 },
        { name: "已审核", num: 13 },
      ], //状态列表
      printVisible: false,
      visible: false,
      labelCol: { span: 6 },
      wrapperCol: { span: 14 },
      busy: true, //列表滚动
      defaultdateList: [],
      searchInfo: {
        jobRecordStatus: null,
        keyWords: "",
        pageRequestModel: {
          pageIndex: 1,
          pageSize: 30,
        },
        startDt: "", //开始时间
        endDt: "", //结束时间
        batchNo: "", //生产批号
        WSType: [], //厂区
        SegmentID: "", //车间
        SegmentIDs: [], //车间
        packingPlanNo: "", //计划单号
      }, //工单列表搜索参数
      list: [], //工单列表
      listNum: 0, //总条数
      listInfo: {}, //选中的列表信息
      mateInfo: [
        { name: "灌装", type: 10 },
        { name: "外包", type: 11 },
        { name: "折叠", type: 12 },
      ], //状态筛选
      mateIdx: 0, //工作集选中项
      mateCurrentInfo: {
        JobRecordList: [],
      }, //选中的工作集
      batchList: [], //工作集列表
      batchDetailList: [], //工作记录明细列表
      polyHeaderList: [], //聚合表单表头
      allPrintShow: false, //批量打印
      allPrintList: [], //批量打印列表

      polyInfo: {}, //默认添加项
      polyList: [], //修改列表
    };
  },
  watch: {
    visible: {
      handler(newVal, oldValue) {
        if (newVal) {
          this.searchInfo.keyWords = "";
        }
      },
      deep: true,
    },
    loadingNum: {
      //请求全部完成再可以操作方法 5- 监听总请求变量为0时表示已经全部赋值完成,可以操控
      handler(newVal) {
        if (newVal == 0) {
          this.loading = false;
        }
      },
      deep: true,
    },
  },
  computed: {
    ...mapState(["startPrint"]),
  },
  methods: {
    //获取厂区列表
    async GetWorkShopTypesAllFun() {
      let that = this;
      let res = await GetWorkShopTypesAll(10);
      if (res.Status == 10000) {
        let wtList = [];
        res.Data.map((item) => {
          wtList.push({ type: item.WSType, name: item.WSName });
        });
        that.WSTypeList = wtList;
      } else {
        that.$message.error(res.Message);
      }
    },
    //选中厂区
    handleChange(value) {
      let that = this;
      if (value) {
        that.GetSegmentsAllFun(that.searchInfo.WSType, true);
      }
    },
    //获取车间列表
    GetSegmentsAllFun: debounce(async function (WSType, ispplist = false) {
      let that = this;
      let SegSegmentID = [
        "1735FA0C-33E4-4B25-AAA2-DE084FB7D1E3",
        "5D494A1E-5F24-4036-9350-2E442A19FE87",
        "CCDB0114-7026-4218-A507-5C00E870B0B3",
        "12FF8C8D-B2DC-4554-AA9B-91703F4AB200",
      ];
      //新建单据的时候，判断类型。只显示对应类型车间
      if (!ispplist && JSON.stringify(that.selectedPPList) !== "{}") {
        switch (that.selectedPPList.OrderType) {
          case 10: //灌包
            SegSegmentID = ["5D494A1E-5F24-4036-9350-2E442A19FE87"];
            break;
          case 11: //包装
            SegSegmentID = ["1735FA0C-33E4-4B25-AAA2-DE084FB7D1E3"];
            break;
          case 12: //折叠
            SegSegmentID = ["CCDB0114-7026-4218-A507-5C00E870B0B3"];
            break;
          case 13: //冲裁
          case 14: //无纺布
          case 15: //挑选
            SegSegmentID = ["12FF8C8D-B2DC-4554-AA9B-91703F4AB200"];
            break;
          default:
            break;
        }
      }
      let res = await GetSegments({
        SegSegmentID: SegSegmentID,
        WSTypeList: WSType,
      });
      if (res.Status == 10000) {
        let wtList = [];
        res.Data.map((item) => {
          wtList.push({ type: item.SegmentID, name: item.SegmentName });
        });
        if (ispplist) {
          that.QSegmentList = wtList;
        } else {
          that.PPQSegmentList = wtList;
        }
      } else {
        that.$message.error(res.Message);
      }
    }),

    //滚动方法
    handleinfiniteOnLoad() {
      this.busy = true;
      setTimeout(() => {
        this.searchInfo.pageRequestModel.pageIndex += 1;
        this.getPackingPlanListFun();
      }, 1000);
    },
    /* 打印页面 */
    onPrint() {
      let isPrint = true;
      this.mateCurrentInfo.JobRecordList.forEach((item) => {
        if (item.VerifyStatus != true) {
          isPrint = false;
        }
      });

      if (!isPrint) {
        this.$message.error("批记录没有审核，请审核后再打印");
        return;
      }
      setTimeout(() => {
        this.$store.commit("upPrintShow", true);
        this.$print(this.$refs.print);
      }, 500);
    },
    async sleep(millisecond) {
      return new Promise((resolve) => {
        setTimeout(() => {
          resolve();
        }, millisecond);
      });
    },
    /* 指定打印页面 */
    async onAppointPrint() {
      let that = this;
      let isPrint = true;
      that.mateCurrentInfo.JobRecordList.forEach((item) => {
        if (item.VerifyStatus != true) {
          isPrint = false;
        }
      });

      if (!isPrint) {
        that.$message.error("批记录没有审核，请审核后再打印");
        return;
      }
      that.$store.commit("upPrintShow", true);

      let data = Object.assign([], that.mateCurrentInfo.JobRecordList);
      //data=data.filter(item=>item.name!='张三');Object.assign({}, data.prizeTypeList)
      console.log(that.mateCurrentInfo.JobRecordList);

      that.mateCurrentInfo.JobRecordList =
        that.mateCurrentInfo.JobRecordList.filter(
          (item) => item.IsPrint == true
        );
      if (
        !that.mateCurrentInfo.JobRecordList ||
        that.mateCurrentInfo.JobRecordList.length == 0
      ) {
        that.$message.error("没有配置指定打印模版");
        that.$store.commit("upPrintShow", false);
        that.mateCurrentInfo.JobRecordList = Object.assign([], data);
        return;
      }
      setTimeout(() => {
        that.$print(that.$refs.print);
      }, 500);
      while (true) {
        await that.sleep(1000);
        if (!that.startPrint) {
          that.mateCurrentInfo.JobRecordList = Object.assign([], data);
          return;
        }
      }
    },
    /* 一键审核 */
    onExamine() {
      let that = this;
      let { JobRecordList } = this.mateCurrentInfo;
      this.$confirm({
        title: `审核`,
        content: `是否审核?`,
        async onOk() {
          let list = [];
          if (JobRecordList.length > 0) {
            list = [
              {
                AssetsID: JobRecordList[0].AssetsID,
                BatchNo: JobRecordList[0].BatchNo,
                JobRecordID: JobRecordList[0].JobRecordID,
              },
            ];
            // JobRecordList.map((item) => {
            //   list.push({ JobRecordID: item.JobRecordID });
            // });
          }
          let res = await verifyJobRecord(list);
          res.Data
            ? that.$message.error(res.Data)
            : that.$message.success("审批成功");
          that.upList();
        },
        onCancel() {},
      });
    },
    /* 弃审 */
    onUnExamine() {
      let that = this;
      let { JobRecordList } = this.mateCurrentInfo;
      this.$confirm({
        title: `弃审`,
        content: `是否弃审?`,
        async onOk() {
          let list = [];
          if (JobRecordList.length > 0) {
            list = [
              {
                AssetsID: JobRecordList[0].AssetsID,
                BatchNo: JobRecordList[0].BatchNo,
                JobRecordID: JobRecordList[0].JobRecordID,
              },
            ];
            // JobRecordList.map((item) => {
            //   list.push({ JobRecordID: item.JobRecordID });
            // });
          }
          let res = await unVerifyJobRecord(list);
          res.Data
            ? that.$message.error(res.Data)
            : that.$message.success("弃审成功");
          that.upList();
        },
        onCancel() {},
      });
    },
    /* 查询列表 */
    upList() {
      this.searchInfo.pageRequestModel.pageIndex = 1;
      this.list = [];
      let { keyWords, batchNo, packingPlanNo } = this.searchInfo;
      if (keyWords != "") {
        this.searchInfo = {
          ...this.searchInfo,
          packingPlanNo: keyWords,
        };
      }
      this.getPackingPlanListFun();
      this.visible = false;
    },
    /* 单据类型筛选 */
    mateFind(type) {
      return this.mateInfo.find((item) => item.type == type);
    },
    //筛选七天时间
    onTimeChange(date, dateString) {
      this.searchInfo = {
        ...this.searchInfo,
        startDt: dateString[0],
        endDt: dateString[1],
      };
    },
    /* 确认搜索 */
    confirm() {},
    /* 修改后更新表格 */
    async upListFun() {
      if (this.mateCurrentInfo.TableType == 1) {
        this.getJobRecordDetailGroupListFun(this.mateCurrentInfo.JobRecordID);
      } else {
        this.getJobRecordDetailListFun(this.mateCurrentInfo.JobRecordID);
      }
    },
    /* 赋值工作集后查询该工作集下的批记录填写信息,批记录用 JobItemIndex字段排序 JobGroup为批记录名称 （建议填写用。隔开 暂时用。分割 */
    async checkBatch(itm, idx) {
      this.mateIdx = idx;
      this.mateCurrentInfo = itm;
      if (!itm.JobRecordList) return;
      itm.JobRecordList.map((item) => {
        if (item.TableType == 1) {
          this.getJobRecordDetailGroupListFun(item.JobRecordID);
        } else {
          this.getJobRecordDetailListFun(item.JobRecordID);
        }
      });
    },
    /* 切换选中工单 */
    checkPacking(item, index) {
      this.listInfo = item;
      this.currentIndex = index;
      this.mateIdx = 0;
      this.getJobRecordToListFun();
    },
    /* 查询工单列表  参数keyWords工单号查询   查询到有值再进行查询该工单的工作集 */
    async getPackingPlanListFun() {
      this.searchInfo.jobRecordStatusStr = this.jobRecordStatusData.join(",");
      // this.searchInfo.jobGroupClass = 1;
      let res = await getPackingPlanList(this.searchInfo);
      this.list = this.list.concat(res.Data.Data);
      this.listNum = res.Data.TotalNumber;
      if (this.list[0]) {
        this.listInfo = this.list[0];
        this.currentIndex = 0;
        this.getJobRecordToListFun();
      } else {
        this.mateCurrentInfo = {
          JobRecordList: [],
        };
        this.currentIndex = 0;
        this.batchList = [];
      }
      if (res.Data.Data.length == 0) {
        this.busy = true;
      } else {
        this.busy = false;
      }
    },

    /* 查询工单的批记录,传入参数选中工单的工单id 如该工单有批记录再操作查询项并通过  JobItemIndex排序*/
    async getJobRecordToListFun() {
      this.batchList = [];

      try {
        this.loading = true;
        let { PackingPlanID, BatchNo } = this.listInfo;
        let res = await getJobRecordToPacking({
          PackingPlanID: PackingPlanID,
          BatchNo: BatchNo,
        });
        /* 赋值默认未选中状态 */
        // this.batchList = res.Data;

        if (res.Data[0]) {
          this.mateCurrentInfo = res.Data[0];
          this.batchList.push(res.Data[0]);
          let { JobRecordList } = res.Data[0];
          JobRecordList.sort((a, b) => a.JobTempletIndex - b.JobTempletIndex);
          for (let i = 1; i < res.Data.length; i++) {
            res.Data[i].JobRecordList.sort(
              (a, b) => a.JobTempletIndex - b.JobTempletIndex
            );
            res.Data[i].JobRecordList.forEach((it) => {
              JobRecordList.push(it);
            });
          }

          this.batchList[0].JobRecordList = JobRecordList;
          if (!JobRecordList || JobRecordList.length == 0) return;

          //请求全部完成再可以操作方法 1- 先将总长度赋值
          this.loadingNum = JobRecordList.length;

          for (const item of JobRecordList) {
            //请求全部完成再可以操作方法 2- 将请求可控为true
            this.isRequest = true;
            if (this.isRequest) {
              if (item.TableType == 1) {
                await this.getJobRecordDetailGroupListFun(item.JobRecordID);
              } else {
                await this.getJobRecordDetailListFun(item.JobRecordID);
              }
            }
          }
        } else {
          this.mateCurrentInfo = {
            JobRecordList: [],
          };
          this.batchList = [];
        }
      } catch (error) {
      } finally {
        this.loading = false;
      }
    },

    /* 查询工作集对应的批记录项  传入工作集id JobRecordID 用于单例列表*/
    async getJobRecordDetailGroupListFun(JobRecordID) {
      try {
        //请求全部完成再可以操作方法 3- 先控制停止循环
        this.isRequest = false;
        let res = await getJobRecordDetailGroupList(JobRecordID);

        if (!res.Success) {
          let { JobRecordList } = this.mateCurrentInfo;
          JobRecordList.forEach((item, index) => {
            if (item.JobRecordID == JobRecordID) {
              item.noData = true;
              item.JobRecordDetaiList = [];
              this.isRequest = false;
              this.loadingNum--;
            }
          });
          return;
        }
        let list = res.Data.sort((a, b) => a.JobItemIndex - b.JobItemIndex);
        list.forEach((item) => {
          item.JobGroup = item.JobGroup.split("。");
          item.JobRecordDetailList = item.JobRecordDetailList.sort(
            (a, b) => a.JobItemIndex - b.JobItemIndex
          );
        });

        if (this.batchList[this.mateIdx]) {
          if (this.batchList[this.mateIdx].JobRecordList.length == 0) return;
          let { JobRecordList } = this.mateCurrentInfo;
          JobRecordList.forEach((item, index) => {
            if (item.JobRecordID == JobRecordID) {
              if (list.length === 0) {
                item.noData = true;
                item.JobRecordDetaiList = [];
              } else {
                item.JobRecordDetaiList = list;
              }

              this.isRequest = false;
              this.loadingNum--;
            }
          });
        }
      } catch (err) {
        if (this.batchList[this.mateIdx]) {
          if (this.batchList[this.mateIdx].JobRecordList.length == 0) return;
          let { JobRecordList } = this.mateCurrentInfo;
          JobRecordList.forEach((item, index) => {
            if (item.JobRecordID == JobRecordID) {
              item.noData = true;
              item.JobRecordDetaiList = [];
              this.isRequest = false;
              this.loadingNum--;
            }
          });
        }
      }
    },
    /* 查询工作集对应的批记录项  传入工作集id JobRecordID 用于聚合列表*/
    async getJobRecordDetailListFun(JobRecordID) {
      try {
        this.isRequest = false;
        let res = await getJobRecordDetailList(JobRecordID);

        if (!res.Success) {
          let { JobRecordList } = this.mateCurrentInfo;
          JobRecordList.map((item, index) => {
            if (item.JobRecordID == JobRecordID) {
              item.noData = true;
              item.JobRecordDetaiList = [];
              item.JobRecordDetaiHList = [];
              this.isRequest = false;
              this.loadingNum--;
            }
          });
          return;
        }
        let stagingHeader = res.Data.filter(
          (item) => item.JobRecordDetailIndex == 1
        );

        stagingHeader = stagingHeader.sort((a, b) => {
          return a.JobItemIndex - b.JobItemIndex;
        });
        let polyHeaderList = polymerizeTitle.handleTitleList(stagingHeader);
        /* 先根据 JobRecordDetailIndex 把每一项排序 */
        let stagingBatchDetailList = res.Data.sort((a, b) => {
          return a.JobRecordDetailIndex - b.JobRecordDetailIndex;
        });
        /* 通过 pop方法获取数组最后一位确定共几行 */
        let batchDetailNum =
          stagingBatchDetailList[stagingBatchDetailList.length - 1]
            .JobRecordDetailIndex;
        /* 定义一个空数组 */
        let detailList = [];

        /* 通过遍历获取最大值添加列表中相对应的JobRecordDetailIndex项为一行 push进detailList数组 */
        for (let index = 1; index <= batchDetailNum; index++) {
          let list = stagingBatchDetailList.filter(
            (fitm) => fitm.JobRecordDetailIndex == index
          );
          detailList.push(list);
        }

        /* 遍历结束后将子项排序后赋值 */
        let detaiArray = detailList.map((ditm) => {
          ditm.sort((a, b) => {
            return a.JobItemIndex - b.JobItemIndex;
          });
          ditm = polymerizeTitle.handleTitleList(ditm);
          return ditm;
        });

        if (this.batchList[this.mateIdx]) {
          if (this.batchList[this.mateIdx].JobRecordList.length == 0) return;
          let { JobRecordList } = this.mateCurrentInfo;
          JobRecordList.map((item, index) => {
            if (item.JobRecordID == JobRecordID) {
              if (detaiArray.length == 0) {
                item.noData = true;
              }
              item.JobRecordDetaiList = detaiArray;
              item.JobRecordDetaiHList = polyHeaderList;
              this.isRequest = false;
              this.loadingNum--;
            }
          });
        }
      } catch (err) {
        if (this.batchList[this.mateIdx]) {
          if (this.batchList[this.mateIdx].JobRecordList.length == 0) return;
          let { JobRecordList } = this.mateCurrentInfo;
          JobRecordList.map((item, index) => {
            if (item.JobRecordID == JobRecordID) {
              item.noData = true;
              item.JobRecordDetaiList = [];
              item.JobRecordDetaiHList = [];
              this.isRequest = false;
              this.loadingNum--;
            }
          });
        }
      }
    },
  },
  mounted() {
    this.defaultdateList = [
      moment().subtract(6, "days").format("YYYY-MM-DD"),
      moment().format("YYYY-MM-DD"),
    ];
    this.searchInfo = {
      ...this.searchInfo,
      startDt: this.defaultdateList[0],
      endDt: this.defaultdateList[1],
    };
    this.getPackingPlanListFun();
    this.GetWorkShopTypesAllFun();
  },
};
</script>

<style lang="less" scoped>
.ant-spin-spinning {
  position: absolute;
  top: calc(50% - 100px);
  left: 50%;
  z-index: 2000;
  color: blue;
}

/deep/.ant-spin-nested-loading {
  height: 100%;
}

/deep/.ant-spin-container {
  height: 100%;
}

.spin-box-div {
  height: 100%;
  display: flex;
  flex-direction: column;
}

//旋转图标颜色
.ant-spin-lg .ant-spin-dot i {
  // background: #fff;
  background: blue;
}

.ant-spin-text {
  color: blue;
}

/deep/.ant-drawer-body {
  padding: 10px;
}

.table-margin {
  margin-bottom: 0.625rem;
}

.currency-box {
  position: relative;

  .section-box-info {
    p {
      margin: 0;
    }
  }
}

.article-list-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 22rem;
  .article-top {
    flex: 1;
  }
}

.batch-printing-right {
  display: flex;
  flex-direction: column;
  width: 0;

  header {
    display: flex;
    overflow-x: auto;
    padding-bottom: 0.6rem;
    border-bottom: 2px solid #f0f2f5;

    .type-list-box {
      display: flex;
      flex-direction: column;
      position: relative;
      cursor: pointer;
      flex: 0 0 25%;
      background: #f0ebeb;
      padding: 0.3125rem;
      border-radius: 0.3125rem;
      margin-right: 0.3125rem;

      .info-box {
        display: flex;
        margin: 0.3rem;
        span:nth-child(3) {
          flex: 2;
        }

        span:nth-child(4) {
          flex: 4;
        }
      }
    }
  }

  section {
    flex: 1;
    overflow: auto;
  }
}

.batch-check-box {
  display: flex;
  justify-content: flex-end;
}

.print-inside {
  page-break-inside: avoid;
}

.active {
  background-color: #dcf0ef !important;
}
</style>
<style media="print">
@media print {
  @page {
    margin: 5mm 10mm 15mm 10mm;
    size: A4 landscape;
    color: #000000 !important;
    /* 在底部居中显示页码 */
    @bottom-center {
      content: counter(page) "/" counter(pages);
    }
  }

  tfoot {
    display: table-footer-group;
  }

  .batch-thead {
    width: 100% !important;
    display: block !important;
  }

  .thead-box {
    display: block !important;
  }

  .table-name {
    width: 100% !important;
    display: block !important;
  }

  .table-name .table-name-td {
    width: 100% !important;
    text-align: center !important;
  }

  .print-box {
    page-break-after: always !important;
  }

  .header-show,
  .header-space,
  .footer,
  .footer-space {
    display: block !important;
  }
}
</style>
